package cn.zwt.wolf.convert;

import cn.zwt.wolf.domain.arrange.Arrange;
import cn.zwt.wolf.domain.position.Position;
import cn.zwt.wolf.domain.rule.Rule;

import java.sql.Timestamp;
import java.util.Date;

/**
 * Created by zhangwt on 16-3-13.
 */
public class RuleInfoConvert {

    public static Arrange convertRule2Arrange(Rule rule,Arrange arrange){
        if (arrange==null){
            arrange =new Arrange();
            arrange.setCreateTime(new Date());
        }
        if (rule != null){
            arrange.setUpdateTime(new Date());
            arrange.setCode(rule.getCode());
            arrange.setRuleId(rule.getId());
        }
        return arrange;
    }

    public static Position convertRule2Position(Rule rule,Position old_position){
        Position position =new Position();
        if (old_position == null){
            position.setCreateTime(new Date());
            position.setValidTime(new Date());
            position.setName(rule.getCode());
            position.setCode(rule.getCode());
        } else {
            position.setCreateTime(new Date());
            position.setValidTime(new Date());
            position.setParentId(old_position.getId());
            String code = String.valueOf(System.currentTimeMillis());
            position.setCode(rule.getCode()+"_"+code);
        }
        if (rule != null){
            position.setUpdateTime(new Date());
        }
        return position;
    }
}
